<?php
/**
 * 自动创建人
 * @author yangdongqi <yangdongqi@hayzone.com>
 * @package lib.behaviors.auto
 */
class CCreator extends CActiveRecordBehavior {
	/**
	 * model所对应的字段名
	 * @var mixed
	 */
	public $attribute = '';
	/**
	 * 所附的值
	 * Enter description here ...
	 * @var string
	 */
	public $value = '';
	
	public function beforeSave($event) {
		if($this->owner->isNewRecord) {
			$value = empty($this->value) ? Yii::app()->user->id : $this->value;
			$this->owner->{$this->attribute} = $value;
		}
	}

}

?>